﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Init {
    import flash.events.*;
    import Engine.Init.*;
    import flash.utils.*;
    import Classes.*;
    import flash.net.*;

    public class QuestSettingsInit extends InitializationAction {

        public static const INIT_ID:String = "ZQuestSettingsInit";

        private static var m_xml:XMLList;
        private static var m_quests:Dictionary = new Dictionary();
        private static var m_rawXml:XML;
        private static var m_questClass:Class;
        private static var m_questUtility:Class;
        private static var m_instance:QuestSettingsInit;

        private var m_settingsUrl:String;

        public function QuestSettingsInit(_arg1:String, _arg2:Class, _arg3:Class){
            super(INIT_ID);
            this.m_settingsUrl = "../questSettings.xml";
            this.m_settingsUrl = _arg1;
            m_questClass = _arg2;
            m_questUtility = _arg3;
            m_instance = this;
        }
        public static function getInstance():QuestSettingsInit{
            return (m_instance);
        }
        public static function getItemByName(_arg1:String):Quest{
            var _local3:XML;
            var _local2:Quest = m_quests[_arg1];
            if (_local2 == null){
                _local3 = getQuestXMLByName(_arg1);
                if (_local3 != null){
                    _local2 = new m_questClass(_local3);
                    m_quests[_arg1] = _local2;
                };
            };
            return (_local2);
        }
        public static function getQuestXMLByName(_arg1:String):XML{
            var list:* = null;
            var result:* = null;
            var nameStr:* = _arg1;
            list = m_rawXml.quest.(@name == nameStr);
            result = null;
            if (list.length()){
                result = list[0];
            };
            return (result);
        }
        public static function get isClientTestingEnabled():Boolean{
            return (!((m_questUtility == null)));
        }
        public static function get getClientTestingClass():Class{
            return (m_questUtility);
        }

        override public function execute():void{
            var _local1:URLLoader = new URLLoader(new URLRequest(this.m_settingsUrl));
            _local1.addEventListener(Event.COMPLETE, this.onConfigXmlLoaded);
        }
        private function onConfigXmlLoaded(_arg1:Event):void{
            var _local2:XML = XML(_arg1.target.data);
            m_rawXml = _local2;
            m_xml = _local2..quests;
            if (m_xml.length > 0){
                m_xml = m_xml[0];
            };
            dispatchEvent(new Event(Event.COMPLETE));
        }

    }
}//package Init 
